<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    @keyup.enter="baTable.onSubmit()"
                    v-model="baTable.form.items"
                    :label-position="config.layout.shrink ? 'top' : 'right'"
                    :label-width="baTable.form.labelWidth + 'px'"
                >
                    <el-form-item label="类别">
                        <el-select v-model="baTable.form.items!.category" placeholder="请选择类别">
                            <el-option v-for="item in categoryList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="物理路径">
                        <el-input v-model="baTable.form.items!.url" type="string"></el-input>
                    </el-form-item>
                    <el-form-item label="宽度">
                        <el-input v-model="baTable.form.items!.imagewidth" type="number" placeholder="请输入图片宽度"></el-input>
                    </el-form-item>
                    <el-form-item label="高度">
                        <el-input v-model="baTable.form.items!.imageheight" type="number" placeholder="请输入图片高度"></el-input>
                    </el-form-item>
                    <el-form-item label="图片类型">
                        <el-input v-model="baTable.form.items!.imagetype" type="string" placeholder="请输入图片类型"></el-input>
                    </el-form-item>
                    <el-form-item label="图片帧数">
                        <el-input v-model="baTable.form.items!.imageframes" type="number" placeholder="请输入图片帧数"></el-input>
                    </el-form-item>
                    <el-form-item label="文件名">
                        <el-input v-model="baTable.form.items!.filename" type="string" placeholder="请输入文件名"></el-input>
                    </el-form-item>
                    <el-form-item label="文件大小">
                        <el-input v-model="baTable.form.items!.filesize" type="number" placeholder="请输入文件大小"></el-input>
                    </el-form-item>
                    <el-form-item label="Mime类型">
                        <el-input v-model="baTable.form.items!.mimetype" type="string" placeholder="请输入Mime类型"></el-input>
                    </el-form-item>
                    <el-form-item label="透析数据">
                        <el-input v-model="baTable.form.items!.extparam" type="string" placeholder="请输入透析数据"></el-input>
                    </el-form-item>
                    <el-form-item label="上传时间">
                        <el-date-picker
                            style="width: 100%"
                            v-model="baTable.form.items!.createtime"
                            type="datetime"
                            placeholder="Select date and time"
                        />
                    </el-form-item>
                    <el-form-item label="存储引擎">
                        <el-input v-model="baTable.form.items!.storage" type="string" placeholder="请输入存储引擎"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit()" type="primary">
                    {{ baTable.form.operateIds!.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { inject, ref, defineExpose } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import { useConfig } from '/@/stores/config'

const config = useConfig()
const baTable = inject('baTable') as baTableClass
const categoryList = ref([])

const { t } = useI18n()

defineExpose({
    categoryList,
})
</script>

<style scoped lang="scss">
.preview-img {
    width: 60px;
    height: 60px;
}
</style>
